-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[POC] Denote the interdependency between parameters in a parameter set #571
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I like this, I am happy to do some immediate testing once this is rolled out to confirm this behavior is accurate. |
Justintime50
approved these changes
Jun 12, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems fine, let's not go overboard with defining these though and only do so for well-defined params like in this case shipment/batches
…pendency between multiple parameters
- Test invalid parameter pair exception
…interdependent (mutually exclusive)
nwithan8
force-pushed
the
required_parameters
branch
from
June 12, 2024 20:30
577cbbd
to
3143950
Compare
jchen293
approved these changes
Jun 12, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
In the
Pickup.Create
parameter set, both theShipment
and theBatch
parameters are marked as "optional". In a vacuum, yes, neither is required on any given API call. However, at least one of them is required for every API call. With our current solution, since both are "optional", it is possible for an end-user to build a parameter set with both excluded, which will ultimately result in a bad request being sent to the API and a resultant error.This PR introduces the concept of a dependency attribute/decorator which can denote the relationship between multiple parameters in a given parameter set. Specifically, the decorator denotes any other parameters that are dependent on the marked parameter, and what the condition is. For the
Shipment
andBatch
example, both parameters are marked with this new attribute, which indicates that, e.g. ifShipment
is set,Batch
must not be set, and ifShipment
is not set,Batch
must be set (and vice versa from theBatch
perspective; ifBatch
is set,Shipment
must not be set, and ifBatch
is not set,Shipment
must be set)These relationships (which can be extended to account for multiple dependent parameters, not just pairs, as well as enforced as one-way relationships) are searched for and evaluated if found during the serialization process. If the condition between parameters in a relationship fails, a local exception is thrown indicating that the pair is invalid. This is done pre-flight, meaning any invalid pair will not make it to the API as it will fail local validation first.
This PR:
InvalidParameterPair
exception typeShipment
andBatch
parameters in thePickup.Create
parameter set, so that one (but not both nor neither) must be provided for each set.Testing
InvalidParameterPair
construction and messagePull Request Type
Please select the option(s) that are relevant to this PR.